package com.funny.learning.english.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.funny.learning.english.R;
import com.funny.learning.english.model.KhopTuEntity;

public class KhopTuAdapter extends BaseAdapter{
	private LayoutInflater inflater;
	private ArrayList<KhopTuEntity> arrData;
	private boolean isEng;
	
	private ClickItemListener clickItemListener;
	
	public KhopTuAdapter(Context context, ArrayList<KhopTuEntity> arrData, boolean isEng) {
		inflater = LayoutInflater.from(context);
		this.arrData = arrData;
		this.isEng = isEng;
	}

	@Override
	public int getCount() {
		return arrData.size();
	}

	@Override
	public KhopTuEntity getItem(int arg0) {
		return arrData.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@SuppressWarnings("null")
	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		if(convertView == null){
			convertView = inflater.inflate(R.layout.khop_tu_item, null);
		}
		TextView tvKhopTu = (TextView)convertView.findViewById(R.id.tvKhopTu);
		
		KhopTuEntity khopTuEntity = arrData.get(arg0);
		
		if(khopTuEntity == null){
			if(isEng){
				tvKhopTu.setText(khopTuEntity.getNameEng());
			}else{
				tvKhopTu.setText(khopTuEntity.getNameViet());
			}
		}
		tvKhopTu.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				
			}
		});
		return convertView;
	}
	
	public ClickItemListener getClickItemListener() {
		return clickItemListener;
	}

	public void setClickItemListener(ClickItemListener clickItemListener) {
		this.clickItemListener = clickItemListener;
	}



	public interface ClickItemListener{
		void clickItem(View view, String id);
	}

}
